// 自定义指令
import { useIntersectionObserver } from '@vueuse/core'
import defauImg from '@/assets/images/200.png'
export default {
  install (app) {
    console.log('install')
    app.directive('imgLazy', {
      // el 绑定的DOM元素
      // binding.value 值
      mounted (el, binding) {
        el.src = defauImg
        const { stop } = useIntersectionObserver(el, ([{ isIntersecting }]) => {
          if (isIntersecting) {
            stop()
            el.src = binding.value
          }
        }, { threshold: 0.1 })
      }
    })
  }
}
